package usw.webserver.entity;

/**
 *
 *
 */
public class ContentType {

	//
	public static final int	CONTENT_TYPE_CSS = 0;
	public static final int CONTENT_TYPE_GIF = 1;
	public static final int CONTENT_TYPE_HTM = 2;
	
	public static final int	CONTENT_TYPE_HTML = 3;
	public static final int CONTENT_TYPE_ICO  = 4;
	public static final int CONTENT_TYPE_JPG  = 5;
	public static final int	CONTENT_TYPE_JPEG = 6;
	public static final int CONTENT_TYPE_PNG  = 7;
	public static final int CONTENT_TYPE_TXT  = 8;
	public static final int CONTENT_TYPE_XML  = 9;
	
	//
	public static final String	STR_CONTENT_TYPE_CSS = "CSS";
	public static final String  STR_CONTENT_TYPE_GIF = "GIF";
	public static final String  STR_CONTENT_TYPE_HTM = "HTM";
	
	public static final String	STR_CONTENT_TYPE_HTML = "HTML";
	public static final String  STR_CONTENT_TYPE_ICO  = "ICO";
	public static final String  STR_CONTENT_TYPE_JPG  = "JPG";
	public static final String	STR_CONTENT_TYPE_JPEG = "JPEG";
	public static final String  STR_CONTENT_TYPE_PNG  = "PNG";
	public static final String  STR_CONTENT_TYPE_TXT  = "TXT";
	public static final String  STR_CONTENT_TYPE_XML  = "XML";
	
	private int		contentType;
	private String 	extension;
	
	public String getExtension() {
		return extension;
	}

	/**
	 * 
	 * @param contentType
	 */
	public void setContentType(int contentType) {
		
		this.contentType = contentType;
		
		switch (this.contentType) {
		case CONTENT_TYPE_CSS:
			extension =  "Content-Type: text/css";
			break;
			
		case CONTENT_TYPE_GIF:
			extension = "Content-Type: image/gif";
			break;
			
		case CONTENT_TYPE_HTM:
		case CONTENT_TYPE_HTML:
			extension =  "Content-Type: text/html";
			break;
			
		case CONTENT_TYPE_ICO:
			extension = "Content-Type: image/gif";
			break;
			
		case CONTENT_TYPE_JPG:
		case CONTENT_TYPE_JPEG:
			extension = "Content-Type: image/jpeg";
			break;
			
		case CONTENT_TYPE_PNG:
			extension = "Content-Type: image/png";
			break;
			
		case CONTENT_TYPE_TXT:
			extension =  "Content-type: text/plain";
			break;
			
		case CONTENT_TYPE_XML:
			extension = "Content-type: text/xml";
			break;
			
		default:
			extension =  "";
			break;
		}
	}

	/**
	 * 
	 * @return
	 */
	public static String 	getContentTypeBySuffix(String strUpperCaseSuffix)
	{
		String	strContentType = "";
		
		switch(strUpperCaseSuffix.toUpperCase())
		{
			case	STR_CONTENT_TYPE_CSS: 
				strContentType =  "Content-Type: text/css";
				break;
		
			case  	STR_CONTENT_TYPE_GIF: 
				strContentType = "Content-Type: image/gif";
				break;
				
			case	STR_CONTENT_TYPE_HTM: 
				strContentType =  "Content-Type: text/html";
				break;
		
			case	STR_CONTENT_TYPE_HTML:
				strContentType =  "Content-Type: text/html";
				break;
				
			case	STR_CONTENT_TYPE_ICO: 
				strContentType = "Content-Type: image/gif";
				break;
				
			case	STR_CONTENT_TYPE_JPG: 
				strContentType = "Content-Type: image/jpeg";
				break;
				
			case	STR_CONTENT_TYPE_JPEG: 
				strContentType = "Content-Type: image/jpeg";
				break;
				
			case	STR_CONTENT_TYPE_PNG:	
				strContentType = "Content-Type: image/png";
				break;
				
			case	STR_CONTENT_TYPE_TXT: 
				strContentType =  "Content-type: text/plain";
				break;
				
			case	STR_CONTENT_TYPE_XML: 
				strContentType = "Content-type: text/xml";
				break;
				
			default:
				strContentType = "";
				break;				
		}
		
		return	strContentType;
	}
	
	/**
	 * 
	 */
	@Override
	public String toString() {
		switch (this.contentType) {
			case CONTENT_TYPE_CSS:
				return "Content-Type: text/css";
				
			case CONTENT_TYPE_GIF:
				return "Content-Type: image/gif";
				
			case CONTENT_TYPE_HTM:
			case CONTENT_TYPE_HTML:
				return "Content-Type: text/html";
				
			case CONTENT_TYPE_ICO:
				return "Content-Type: image/gif";
				
			case CONTENT_TYPE_JPG:
			case CONTENT_TYPE_JPEG:
				return "Content-Type: image/jpeg";
				
			case CONTENT_TYPE_PNG:
				return "Content-Type: image/png";
				
			case CONTENT_TYPE_TXT:
				return "Content-type: text/plain";
				
			case CONTENT_TYPE_XML:
				return "Content-type: text/xml";
				
			default:
				return null;
		}
	}
}
